package net.steam.easyjoboa.biz.impl;

import java.util.List;

import net.steam.easyjoboa.biz.TicklerBiz;
import net.steam.easyjoboa.dao.TicklerDao;
import net.steam.easyjoboa.entity.Tickler;

public class TicklerBizImpl implements TicklerBiz{
	
	private TicklerDao ticklerDao;
	
	public TicklerDao getTicklerDao() {
		return ticklerDao;
	}
	public void setTicklerDao(TicklerDao ticklerDao) {
		this.ticklerDao = ticklerDao;
	}


	/**
	 * 添加报销申请
	 */
	public Integer add(Tickler ticker) {
		int rows=0;
		try {
			rows= ticklerDao.addEntity(ticker);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rows;
	}
	
	/**
	 * 批量删除
	 */
	public void delete(int[] id) {
			ticklerDao.deleteAll(id);
	}
	
	/**
	 * 根据userId查找个人日程安排
	 */
	public List<Tickler> getTicklerByUserId(Integer userId) {
		String hql=String.format("from Tickler tk where tk.employee.userId=%s order by TDate desc",userId);
		return ticklerDao.find(hql);
	}

	/**
	 * 按范围搜索个人日程
	 */
	public List<Tickler> searchSchedule(Integer userId,String startDate, String endDate) {
		String hql=String.format
		("from Tickler tk where tk.employee.userId=%s and to_char(tk.TDate,'yyyy-MM-dd') between '%s' and '%s' order by TDate desc",
				userId,startDate,endDate);
		return ticklerDao.find(hql);
	}

}
